/**
 * Copyright (c) 快宝网络 kuaidihelp.com Co., Ltd. All Rights Reserved 禁止外泄以及用于其它的商业用途
 */

import type { Field } from './type';

export const transStatus: (status: string) => string = (status) => {
  switch (status.toString()) {
    case '-1':
      return '异常单';
    case '0':
      return '待处理';
    case '1':
      return '待接单（派单中）';
    case '2':
      return '已接单（待取货）';
    case '3':
      return '取货中';
    case '4':
      return '配送中';
    case '5':
      return '已完成';
    case '6':
      return '已取消';
    case '7':
      return '派单失败';
    default:
      return '--';
  }
};

export const formatDistance: (distance: number) => string = (distance) => {
  if (distance < 1000) {
    return `${distance} 米`;
  } else {
    return `${parseFloat((distance / 1000).toFixed(3))} 公里`;
  }
};

export const createTips = (str?: string, type?: string, rules: boolean = true) => {
  const prefix = type === 'select' ? '请选择' : '请输入';
  const message = prefix + str;
  return {
    placeholder: message,
    rules: rules ? [{ required: true, message }] : [],
  };
};
export const getShowStatus = (keys: string[], key: string) => keys.includes(key);

export const createFormFields = (FieldList: Field[]) => {
  return FieldList.map((item: Field, index: number) => {
    const { message, node, rules, ...rest } = item;
    return {
      ...rest,
      id: `node_${index}`,
      node: item.node || 'input',
      width: item.width || 200,
      ...createTips(message, node, rules),
    };
  });
};
